{% load static %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}数据监控平台{% endblock %}</title>
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'css/bootstrap-icons.css' %}" rel="stylesheet">
    <link href="{% static 'css/style.css' %}" rel="stylesheet">
    <link rel="icon" href="{% static 'img/favicon.ico' %}">
    {% block extra_css %}{% endblock %}
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="{% url 'subscription_dashboard' %}">
            <i class="bi bi-graph-up"></i> 数据监控平台
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'datasource_list' %}">
                        <i class="bi bi-database"></i> 数据源
                    </a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="subscriptionDropdown" role="button"
                       data-bs-toggle="dropdown">
                        <i class="bi bi-bell"></i> 订阅管理
                    </a>
                    <ul class="dropdown-menu">
                        <li>
                            <a class="dropdown-item" href="{% url 'opcua_subscription_list' %}">
                                <i class="bi bi-diagram-3"></i> OPC UA 订阅
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="{% url 'mqtt_subscription_list' %}">
                                <i class="bi bi-broadcast"></i> MQTT 订阅
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'alarm_list' %}">
                        <i class="bi bi-exclamation-triangle"></i> 报警记录
                    </a>
                </li>
            </ul>
            <ul class="navbar-nav ms-auto">
                {% if user.is_authenticated %}
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
                           data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ user.username }} {{ user.first_name }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <!-- 添加后台数据管理菜单项 -->
                            {% if user.is_superuser or user.is_staff %}
                                <li>
                                    <a class="dropdown-item" href="{% url 'admin:index' %}">
                                        <i class="bi bi-gear-fill"></i> 数据管理
                                    </a>
                                </li>
                            {% endif %}
                            <li>
                                <a class="dropdown-item" href="{% url 'profile' %}">
                                    <i class="bi bi-person-fill"></i> 个人资料
                                </a>
                            </li>
                            <li>
                                <a class="dropdown-item" href="{% url 'password_change' %}">
                                    <i class="bi bi-pen-fill"></i> 修改密码
                                </a>
                            </li>

                            <div class="dropdown-divider"></div>
                            <form method="post" action="{% url 'logout' %}">
                                {% csrf_token %}
                                <button type="submit" class="dropdown-item text-danger">
                                    <i class="bi bi-box-arrow-right"></i> 注销
                                </button>
                            </form>
                        </ul>
                    </li>
                {% else %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'login' %}">
                            <i class="bi bi-box-arrow-in-right"></i> 登录
                        </a>
                    </li>
                {% endif %}
            </ul>
        </div>
    </div>
</nav>

<main class="py-4">
    {% if messages %}
        <div class="container">
            {% for message in messages %}
                <div class="alert alert-{{ message.tags }} alert-dismissible fade show">
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            {% endfor %}
        </div>
    {% endif %}

    {% block content %}{% endblock %}
</main>

<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
{% block extra_js %}{% endblock %}
</body>
</html> 